package cn.mrcode.fd.blog.common;

import cn.mrcode.fd.blog.task.CacheAutoScanTask;

import java.util.HashMap;

/**
 * 业务常量
 * @author zhuqiang
 * @version V1.0
 * @date 2015/12/14 21:34
 */
public class BusConstant {
    /** session 中保存的key */
    public static class SessionKey{
        /** 用户信息*/
        public static final String USER_INFO = "USER_INFO";
    }
    public static class CookiesKey{
        /** 博客访问量 */
        public static final String COOKIE_BLOG_VISITS_NUM = "COOKIE_BLOG_VISITS_NUM";
    }

    public static class Url{

    }

    public static class Sysuser{
        /** 系统id */
        public static final String SYS_USER_ID = "A000000000000000000000000000000";
        /** 测试用户id */
        public static final String TEST_USER_ID_2 = "A000000000000000000000000000001";
    }

    /** 禁用账户列表 */
    public static class DisableAccount{
        private static HashMap<String,String> MAP = new HashMap<String, String>();
        static {

        }

        /**
         * 该账户是否被禁用
         * @param account
         * @return
         */
        public static boolean isDisable(String account){
            return MAP.containsKey(account);
        }
    }

    /** 文章状态 */
    public static class ArticleStatus{
        /** 中英映射 */
        public static final HashMap<Integer,String> enMap = new HashMap<>();
        /** 状态转移链:key=状态，value=可以转义的状态，中间用逗号隔开 */
        public static final HashMap<Integer,String> transferChainMap = new HashMap<>();

        /** 彻底删除 */
        public static final int DEL = -1;
        /** 审核中 */
        public static final int AUDIT = 0;
        /** 正常发布状态 */
        public static final int NORMAL = 1;
        /** 草稿箱 */
        public static final int DRAFTS = 2;
        /** 回收站 */
        public static final int RECYCLE = 3;
        /** 被屏蔽/被投诉 */
        public static final int SHIELD = 4;
        static {
            enMap.put(AUDIT,"审核中");
            enMap.put(NORMAL,"正常");
            enMap.put(DRAFTS,"草稿箱");
            enMap.put(RECYCLE,"回收站");
            enMap.put(SHIELD,"被屏蔽/被投诉");

            transferChainMap.put(AUDIT,NORMAL + "," + RECYCLE);
            transferChainMap.put(NORMAL,RECYCLE + "," + SHIELD);
            transferChainMap.put(DRAFTS,RECYCLE + "," + NORMAL);
            transferChainMap.put(RECYCLE,NORMAL + "");
            transferChainMap.put(SHIELD,AUDIT + "");
            transferChainMap.put(RECYCLE,DEL + "");
        }

        /**
         * 判定状态转移是否合法
         * @param currentStatus
         * @param toNewStatus
         * @return
         */
        public static boolean isCanTransfer(int currentStatus, int toNewStatus){
            if(!transferChainMap.containsKey(currentStatus)){
                return false;
            }

            String chain = transferChainMap.get(currentStatus);
            return chain.contains(toNewStatus+"");
        }
    }

    /** 用户的一些默认配置 */
    public static class DefaultConfig{
        /** 默认头像 **/
        public static final String HEAD_IMG= CacheAutoScanTask.getValue("res_path_rel_img","default_head_img");

        /** 博客配置：默认用户背景配置 */
        public static final String USER_HANDER_BG = CacheAutoScanTask.getValue("res_path_rel_img","default_userhanderbg");
        /** 默认博客秀 **/
        public static final String BLOG_SHOW = CacheAutoScanTask.getValue("res_path_rel_img","default_blog_show");
    }
}
